{extend name="member/common/shop_layout" /}

{block name="content"}

<div class="ncm-flow-layout">
  <div class="ncm-flow-container">
    <div class="title"><a href="javascript:history.go(-1);" class="ncbtn-mini fr"><i class="icon-reply"></i>返&nbsp;回</a>
      <h3>对商品进行评价</h3>
    </div>
    <form id="evalform" method="post" action="member/Evaluate/<?php echo $cur_action;?>?order_id=<?php echo I('order_id');?>">
      <input type="hidden" name="form_submit" value="ok" />
      <div class="alert alert-block">
        <h4>操作提示：</h4>
        <ul>
          <li>评价信息最多填写250字，请您根据本次交易，给予真实、客观地评价；您的评价将是其他会员的参考。</li>
          <li><?php echo $ruleexplain;?></li>
          <li>店铺动态评分默认为“5分”，您可以根据本次交易情况给予商家评分，<span class="orange"> 一旦提交后不能修改。</span></li>
          <li>图片上传请使用jpg\jpeg\png等格式、单张大小不超过1M的图片，最多可发布5张晒图，上传后的图片也将被保存在个人主页相册中以便其它使用。</li>
        </ul>
      </div>
      <div class="tabmenu">
        <ul class="tab">
          <li class="active"><a href="javascript:void(0);">对购买过的商品评价</a></li>
        </ul>
      </div>
      <table class="ncm-default-table mb30">
        <tbody>
        <?php if(!empty($order_goods)){?>
        <?php foreach($order_goods as $goods){?>
        <tr class="bd-line">
          <td class="w20"></td>
          <td class="pic-mode w200"><div class="pic-thumb"><a href="shop/Goods/index?goods_id=<?php echo $goods['goods_id']; ?>" target="_blank"><img src="<?php echo $goods['goods_image_url']; ?>"/></a></div>
            <dl class="goods-name">
              <dt><a href="shop/Goods/index?goods_id=<?php echo $goods['goods_id'];?>" target="_blank" title="<?php echo $goods['goods_name'];?>"><?php echo $goods['goods_name'];?></a></dt>
              <dd title="<?php echo $goods['goods_spec'];?>"><?php echo $goods['goods_spec'];?></dd>
            </dl></td>
          <td valign="top" class="tl"><div class="ncgeval">商品评分：
            <div class="raty vm">
              <input nctype="score" name="goods[<?php if ($cur_action != 'add_vr') { echo $goods['rec_id'];} else { echo $goods['goods_id'];}?>][score]" type="hidden">
            </div>
          </div>
            <textarea name="goods[<?php if ($cur_action != 'add_vr') { echo $goods['rec_id'];} else { echo $goods['goods_id'];}?>][comment]" cols="150" class="w450 mt10 mb10 h40" placeholder="请输入要评价的内容，不要超过150个字符。"></textarea>
            <div class="show-pic">
              <?php if ($cur_action != 'add_vr') {?>
              <div class="ncm-upload-btn fl"> <a href="javascript:void(0);"> <span>
                  <input type="file" hidefocus="true" size="1" class="input-file" name="file" id="file<?php echo $goods['rec_id'];?>" multiple>
                  </span>
                <p><i class="icon-camera" data_type="0"></i>买家晒图</p>
              </a> </div>
              <div class="ml5 mt5 fl">限5张</div>
              <?php }?>
              <span class="fr mr10 mt5">
                <input type="checkbox" class="checkbox vm" name="goods[<?php if ($cur_action != 'add_vr') { echo $goods['rec_id'];} else { echo $goods['goods_id'];}?>][anony]">
                &nbsp;匿名评价</span>
              <div class="evaluation-image">
                <ul nctype="ul_evaluate_image<?php echo $goods['rec_id'];?>" data-count='0'>
                </ul>
              </div>
            </div></td>
        </tr>
        <?php }?>
        <?php }?>
        </tbody>
      </table>
      <?php if (!$store_info['is_own_shop'] && $cur_action != 'add_vr') { ?>
      <div class="tabmenu">
        <ul class="tab">
          <li class="active"><a href="javascript:void(0);">对该店此次服务的评分</a></li>
        </ul>
      </div>
      <?php } ?>
      <div class="ncm-default-form">
        <?php if (!$store_info['is_own_shop'] && $cur_action != 'add_vr') { ?>
        <dl>
          <dt>宝贝与描述相符：</dt>
          <dd>
            <div class="raty-x2">
              <input nctype="score" name="store_desccredit" type="hidden">
            </div>
          </dd>
        </dl>
        <dl>
          <dt>卖家的服务态度：</dt>
          <dd>
            <div class="raty-x2">
              <input nctype="score" name="store_servicecredit" type="hidden">
            </div>
          </dd>
        </dl>
        <dl>
          <dt>卖家的发货速度：</dt>
          <dd>
            <div class="raty-x2">
              <input nctype="score" name="store_deliverycredit" type="hidden">
            </div>
          </dd>
        </dl>
        <?php } ?>
        <div class="bottom">
          <label class="submit-border">
            <input id="btn_submit" type="button" class="submit" value="提交"/>
          </label>
        </div>
      </div>
    </form>
  </div>
  <div class="ncm-flow-item">
    <?php if (!$store_info['is_own_shop']) { ?>

    {include file="member/evaluate/store_info"}
    <?php } ?>
  </div>
</div>
<script type="text/javascript" src="__SITE_RESOURCE__/js/jquery.raty/jquery.raty.min.js"></script>
<?php if ($cur_action != 'add_vr') {?>
<script type="text/javascript" src="__SITE_RESOURCE__/js/fileupload/jquery.iframe-transport.js" charset="utf-8"></script>
<script type="text/javascript" src="__SITE_RESOURCE__/js/fileupload/jquery.ui.widget.js" charset="utf-8"></script>
<script type="text/javascript" src="__SITE_RESOURCE__/js/fileupload/jquery.fileupload.js" charset="utf-8"></script>
<?php }?>
<script type="text/javascript">
    $(function(){
        $('.raty').raty({
            path: "__SITE_RESOURCE__/js/jquery.raty/img",
            click: function(score) {
                $(this).find('[nctype="score"]').val(score);
            }
        });

        $('.raty-x2').raty({
            path: "__SITE_RESOURCE__/js/jquery.raty/img",
            starOff: 'star-off-x2.png',
            starOn: 'star-on-x2.png',
            width: 170,
            click: function(score) {
                $(this).find('[nctype="score"]').val(score);
            }
        });


        $('#btn_submit').on('click', function() {
            ajaxpost('evalform', '', '', 'onerror')
        });
        <?php if ($cur_action != 'add_vr') {?>
        <?php if(!empty($order_goods)){?>
            <?php foreach($order_goods as $goods){?>
                <?php $param_id = $cur_action != 'add_vr' ? $goods['rec_id'] : $goods['goods_id'];?>
                    // 图片上传
                    $('#file<?php echo $param_id;?>').fileupload({
                        dataType: 'json',
                        url: '<?php echo url('shop/Snsalbum/swfupload');?>',
                        formData: '',
                        add: function (e,data) {
                            var $count = parseInt($('ul[nctype="ul_evaluate_image<?php echo $param_id;?>"]').attr('data-count'));
                            if ($count >= 5) {
                                return false;
                            }
                            $('ul[nctype="ul_evaluate_image<?php echo $param_id;?>"]').attr('data-count', $count +1);
                            data.formData = {category_id:<?php echo $ac_id;?>};
                            data.submit();
                        },
                        done: function (e,data) {
                            if(data.result.state == 'true') {
                                $('<li>' +
                                    '<div class="upload-thumb" nctype="image_item">' +
                                    '<img src="' + data.result.file_url + '"><input type="hidden" nctype="input_image" name="goods[<?php echo $param_id;?>][evaluate_image][]" value="' + data.result.file_name + '" >' +
                                    '<a href="javascript:;" nctype="del" data-file-id="' + data.result.file_id + '" class="del" title="移除">X</a>' +
                                    '</div></li>').appendTo('ul[nctype="ul_evaluate_image<?php echo $param_id;?>"]');
                            } else {
                                showError(data.result.message);
                            }
                        }
                    });
                <?php }?>
            <?php }?>
            $('ul[nctype^="ul_evaluate_image"]').on('click', '[nctype="del"]', function() {
                album_pic_del($(this).attr('data-file-id'));
                var $item_li = $(this).parents('li:first');
                var $item_ul = $item_li.parents('ul:first');
                $item_li.find('[nctype="input_image"]').val('');
                $item_li.remove();
                $item_ul.attr('data-count', $item_ul.attr('data-count') -1);
            });

            var album_pic_del = function(file_id) {
                var del_url = "<?php echo url('shop/Snsalbum/album_pic_del');?>";
                del_url += '&id=' + file_id;
                $.get(del_url);
            }
            <?php }?>
    });
</script>
{/block}


